<?php
namespace app\api\controller;

class Tuisong extends Controller
{

    public function initialize()
    {
        $this->user = $this->getShangUser();   // 商户信息
        $this->imgadess = $this->pcUrl();
    }

        public function img_qrcode($size=300,$text='',$logo_path="static/image/logo.jpg",$logo_width=100)
    {
        $app_key = '0f824ee4e545dfda3da896b1';
        $master_secret = '257b65928c57b389268d9651';

        $client  =  new  \JPush\Client($app_key,$master_secret);
        $push = $client->push();



        $cid = '*****';
        $platform = array('ios', 'android');
        $alert = 'Hello JPush';
        $tag = array('tag1', 'tag2');
        $regId = array('rid1', 'rid2');
        $ios_notification = array(
            'sound' => 'hello jpush',
            'badge' => 2,
            'content-available' => true,
            'category' => 'jiguang',
            'extras' => array(
                'key' => 'value',
                'jiguang'
            ),
        );

        $content = 'Hello World';
        $message = array(
            'title' => 'hello jpush',
            'content_type' => 'text',
            'extras' => array(
                'key' => 'value',
                'jiguang'
            ),
        );
        $options = array(
            'sendno' => 100,
            'time_to_live' => 100,
            'override_msg_id' => 100,
            'big_push_duration' => 100
        );
        $response = $push->setCid($cid)
            ->setPlatform($platform)
            ->addTag($tag)
            ->addRegistrationId($regId)
            ->iosNotification($alert, $ios_notification)
            ->message($content, $message)
            ->options($options)
            ->send();
        print_r($response);
        //echo 111;
        exit;


    }



    public function wuliu()
    {
        $info = $this->request->post();
        if(empty($info['orderid'])){
            return $this->renderError(1001,'缺少必须参数');
        }
        $where['order_id'] = $info['orderid'];
        $model = new \app\api\model\Order();
        $order = $model->orderpul($where);
        $express_no= '';
        if(!empty($order))
        {
            $express_no = $order['express_no'];
        }

        $url = 'https://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text='.$express_no;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($curl);
        curl_close($curl);
       // return  ($data);

        $wuliu = json_decode($data,true);
        $wulname = '';
        if(!empty($wuliu)){
            if(count($wuliu['auto'])>0){
                $wulname = $wuliu['auto'][0]['comCode'];
            }
        }

        $url = 'https://m.kuaidi100.com/query';//post查询条件
        //$fields = 'postid=75159251697701&id=1&valicode=&temp=0.006414744938973982&type=zhongtong&phone=&token=&platform=MWWW';
        $fields = 'postid='.$express_no.'&id=1&valicode=&temp=0.006414744938973982&type='.$wulname.'&phone=&token=&platform=MWWW';

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 60,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_HTTPHEADER => array(
                "accept: */*",
                "accept-encoding: gzip, deflate",
                "accept-language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,ja;q=0.2",
                "cache-control: no-cache",
                "connection: keep-alive",
                "content-type: application/x-www-form-urlencoded",
                //"cookie: $cookie",
                "origin: http://www.**.com",
                "pragma: no-cache",
                "referer: http://www.****.com",
                "user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36",
                "x-requested-with: XMLHttpRequest"
            ),
        ));

//url
        curl_setopt($curl, CURLOPT_URL, $url);
//post fields
        curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($curl, CURLOPT_COOKIE, 'csrftoken=mRRKbKMm34ocwmyBGNSnLp4Tk0zLILC9Tihjg0P2dX0; Hm_lvt_22ea01af58ba2be0fec7c11b25e88e6c=1564563968; WWWID=WWW31AAF56D6B1EBE11C65DA00F8BC534D9; Hm_lpvt_22ea01af58ba2be0fec7c11b25e88e6c=1564566015');
        $response = curl_exec($curl);
        $err = curl_error($curl);
        $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $sda = json_decode($response,true);

        $sda['order_no'] = $order['order_no'];
        $sda['express_no'] = $express_no;
        return $this->renderSuccess(1000,'成功',$sda);

    }


    public  function duanxin()
    {
        //$url = 'http://v.juhe.cn/sms/send';//post查询条件
        //$fields = 'postid=75159251697701&id=1&valicode=&temp=0.006414744938973982&type=zhongtong&phone=&token=&platform=MWWW';
        //$fields = 'mobile=18510852363&tpl_id=176606&tpl_value=%23code%23%3D654654&key=9cace9e00efd9d51f12f2c255e4a40be';
        //$url = 'http://106.14.255.200:8888/sms.aspx';
        //$fields = 'action=send&userid=12&account=艺人装修&password=密码&mobile=18510852363&content=12345678912&sendTime=&extno=';
        $url = 'http://utf8.api.smschinese.cn/';
        $fields = 'Uid=艺人装修平台&Key=d41d8cd98f00b204e980&smsMob=18510852363&smsText=【验证码】验证码是123456';
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 60,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_HTTPHEADER => array(
                "accept: */*",
                "accept-encoding: gzip, deflate",
                "accept-language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,ja;q=0.2",
                "cache-control: no-cache",
                "connection: keep-alive",
                "content-type: application/x-www-form-urlencoded",
                //"cookie: $cookie",
                "origin: http://www.**.com",
                "pragma: no-cache",
                "referer: http://www.****.com",
                "user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36",
                "x-requested-with: XMLHttpRequest"
            ),
        ));

//url
        curl_setopt($curl, CURLOPT_URL, $url);
//post fields
        curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($curl, CURLOPT_COOKIE, 'csrftoken=mRRKbKMm34ocwmyBGNSnLp4Tk0zLILC9Tihjg0P2dX0; Hm_lvt_22ea01af58ba2be0fec7c11b25e88e6c=1564563968; WWWID=WWW31AAF56D6B1EBE11C65DA00F8BC534D9; Hm_lpvt_22ea01af58ba2be0fec7c11b25e88e6c=1564566015');
        $response = curl_exec($curl);
        $err = curl_error($curl);
        $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        print_r($response);exit;
    }

}